package it.sources.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import it.sources.blog.domain.Article;
import it.sources.blog.domain.query.ArticleQuery;
import it.sources.blog.mapper.ArticleMapper;
import it.sources.blog.service.IArticleService;
import it.sources.untile.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
@CacheConfig(cacheNames = "article")
public class ArticleServiceImpl implements IArticleService {
    @Autowired
    private ArticleMapper ump;
    @Override
    public List<Article> findAll() {
        return ump.findAll();
    }

    @Override
    public Article findOne(Long id) {
        return ump.findOne(id);
    }
@CacheEvict(key = "typeTree")
    @Override
    public void delet(Long id) {
        ump.delet(id);
    }

    @CacheEvict(key = "typeTree")
    @Override
    public void upDate(Article article) {
        ump.upDate(article);
    }
    @CacheEvict(key = "typeTree")
    @Override
    public void add(Article article) {
        ump.add(article);
    }

    @CacheEvict(key = "typeTree")
    @Override
    public R pathDele(Long[] id) {
        ump.pathDele(id);
        return R.success();
    }

    @Override
    public PageInfo<Article> queryPage(ArticleQuery articleQuery) {
        PageHelper.startPage(articleQuery.getCurrentPage(), articleQuery.getPageSize());
        List<Article> articles = ump.queryPage(articleQuery);
        PageInfo<Article> info = new PageInfo<Article>(articles);
        return  info;
    }
}
